import { request } from '@umijs/max';
import { stringify } from 'qs';

//搜索文章
export const searchArticle = (params:{
  current: number;
  size: number;
  /**
   * 文章标题/标签/摘要
   */
  value: string;
}) =>
  request(`/article/search?${stringify(params)}`, {
    method: 'GET',
  });
//新增或者修改文章
export const editArticle = (params: {
    /**
     * 文章内容
     */
    content?: null | string;
    /**
     * 文章ID
     */
    id?: number | null;
    /**
     * 文章封面
     */
    images?: null | string;
    /**
     * 状态：0：草稿箱，1：待审核，2：已发布，3：驳回
     */
    status?: number | null;
    /**
     * 文章摘要
     */
    summary?: null | string;
    /**
     * 文章标签
     */
    tags?: null | string;
    /**
     * 文章标题
     */
    title?: null | string;
    /**
     * 文章分类
     */
    type?: null | string;
}) =>
request('/article/add-or-update', {
  method: 'POST',
  data: params,
});


//阅读文章

export const getArticleInfo = (id:string) =>request(`/article/view/${id}`,{
  method:'GET',
})

//根据id删除文章
export const delArticle = (id:string) =>request(`/article/${id}`,{
  method:'DELETE',
})




//获取文章一级评论
export const getCommentList = (params:{
    /**
     * 文章ID
     */
    articleId?: number | null;
    pageCurrent: number | null;
    pageSize: number | null;
}) =>request(`/comment/page-list`,{
  method:'POST',
  data:params,
})
//获取文章二级评论
export const getReCommentList = (params:{
      /**
     * *
     * 一级评论ID
     */
      commentId?: number | null;
      pageCurrent: number | null;
      pageSize: number | null;
}) =>request(`/reply/page-list`,{
  method:'POST',
  data:params,
})

//发布评论
export const addComment = (params:{
      /**
     * 文章ID
     */
      articleId?: number | null;
      /**
       * 评论的内容
       */
      content?: null | string;
}) =>request(`/comment/add`,{
  method:'POST',
  data:params,
})

//发布二级评论
export const addReComment = (params:{
  /**
     * 一级评论ID
     */
  commentId?: number | null;
  /**
   * 内容
   */
  content?: null | string;
  /**
   * 回复目标用户ID
   */
  targetUserId?: number | null;
}) =>request(`/reply/add`,{
  method:'POST',
  data:params,
})


//根据id获取文章信息
export const getArticleDetail = (articleId:string) =>request(`/article/${articleId}`,{
  method:'GET',
})

//根据用户id获取文章列表
export const getArticleListByUserId = (userId:string) =>request(`/article/list?userId=${userId}`)

//根据id获取用户信息
export const getUserDetailByUserId = (userId:string) =>request(`/sysUser/getInfo/${userId}`)

//根据用户id获取公开的收藏夹列表
export const getFavoitesFolderListByUserId = (userId:string) =>request(`/favorites_folders/public-list?userId=${userId}`)

//获取我的文章列表
export const getMyArticleList = (params:{status:number}) => request(`/article/myList?${stringify(params)}`, {
  method: "GET",
});


//点赞文章
export const addLikeArticle = (articleId:string) =>request(`/like/add/${articleId}`,{
  method: "POST",
})
//取消点赞文章
export const delLikeArticle = (articleId:string) =>request(`/like/del/${articleId}`,{
  method: "POST",
})
